package csdn.jihe.li08;

public class Student implements Comparable<Student>{

    private String name;
    private int age;
    private int score;
    public Student(){}
    public Student(String name, int age, int score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }
    //set、get
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    public int getScore() {
        return score;
    }
    public void setScore(int score) {
        this.score = score;
    }
    @Override
    public String toString() {
        return "\nStudent [name=" + name + ", age=" + age + ", score=" + score + "]";
    }
//自然排序
    @Override
    public int compareTo(Student o) {
        int num;
        if(this.name=="tom"){return -1;}
        //name降序
        num=o.name.compareTo(this.name);
        if(num==0){
            //age升序
            num=this.age-o.age;
            if(num==0){
                //score降序
                num=o.score-this.score;
            }
        }
        return num;
    }
}
